#ifndef UANALYSERWIDGET_H
#define UANALYSERWIDGET_H

#include <QtGui>
#include <QtGui/QWidget>
#include <QtSvg>
#include "uanalyseraudioinput.h"

class uAnalyserRenderer;
class uAnalyserControls;
class uAnalyserChannel;
class uAnalyserMainWindow;

enum uAnalyserMode
{
    SvgViewerMode,
    OscilloscopeMode
};

//MOST IMPORTANT CLASS IN WHOLE APPLICATION
//If you want to develop this application you will surely have to modify this class.
// Purpose of this class:
// - the container for "the screen"(screenScene), the oscilloscope setting controls(operatorPanel) and channels(ui controls + signal information + traces)
// - acts as a sort of "interface" between screenScene, operatorPanel and channels
// Supplies following functionalities:
// - loading CSV files (should be the separate class...)
// - saving to SVG
// - oscilloscope - very temporary(only one-channel microphone input and no triggering options)
//   besides oscilloscope also should be the separate class
class uAnalyserWidget : public QWidget
{
    Q_OBJECT

public:
    uAnalyserWidget(QWidget *parent = 0);
    ~uAnalyserWidget();
    void paint(QPainter *) {}

    double getTimeBase();
    QVector<double> timeSweep;

public slots:
    uAnalyserChannel* addNewChannel(bool generateExampleWave=true); //add channel(flat or with example sine wave)
    uAnalyserChannel* addNewChannel(QVector<double> &v); //add channel with wave passed as parameter
    uAnalyserChannel* addNewTestChannel() { return addNewChannel(true); }

    void removeChannel(); //remove channel - called ONLY by signals from "Remove" buttons assigned to each channel
    void refreshChannels(); //redraws all channels on osciloscope

    void loadCsvFile(); //reads and displays CSV file
    void saveSvgFile(); //saves current contents of screen to SVG file(might be anything - oscilloscope channels, CSV, test waves)

    void openOscilloscope(); //turns on oscilloscope functionality
    void pauseOscilloscope(bool p) { audioInput->pauseRecording(p); } //pause(1)/start(0) oscilloscope view
    void closeOscilloscope(); //turns off oscilloscope functionality

    void setTimeBase(double t_base);
    void showAxes(int); //turn axes on/off (horizontal and diagonal)
    void showGrid(int); //turn grid on/off (10x10)

private:
    uAnalyserMode mode;

    uAnalyserMainWindow* mainWindow;
    uAnalyserControls *operatorPanel;

    uAnalyserRenderer *screenScene;
    QGraphicsView *screenView;

    QLinkedList<uAnalyserChannel *> channels;
    uAnalyserAudioInput *audioInput;
    int oscilloscopeSampleRate;
    int oscilloscopeBufferSize;

    double timeBase;
};

//top-level user interface widget.
//It's parent/container for uAnalyserWidget and it adds menu to application window
class uAnalyserMainWindow : public QMainWindow
{
    Q_OBJECT

public:
    uAnalyserMainWindow();
    void newChannelEnable(bool flag) { newChannelAct->setEnabled(flag); }
private:
    void createActions();
    void createMenus();

    uAnalyserWidget *mainWidget;

    QMenu *fileMenu;
    QAction *newChannelAct;
    QAction *loadCsvAct;
    QAction *saveSvgAct;
    QAction *oscilloscopeAct;
    QAction *exitAct;
};



#endif // UANALYSERWIDGET_H
